﻿using System;
using System.Windows.Controls;


namespace SQLDeploy.Builder.Controls.Environments
{
    public class ConnectionValidationRule : ValidationRule
    {

        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string val = value as string;
            if (string.IsNullOrEmpty(val))
                return new ValidationResult(false, "Name cannot be empty");

            if (string.IsNullOrWhiteSpace(val))
                return new ValidationResult(false, "Name cannot be empty");

            if (AddDialog._Connections.NameExists(val))
                return new ValidationResult(false, "Name '" + val + "' already exists in connections file.");

            return new ValidationResult(true, null);
        }
    }
}
